import 'package:flutter/material.dart';
import 'package:fzcgx_app/common/adapter_utils.dart';
import 'package:fzcgx_app/provider/provider_widget.dart';
import 'package:fzcgx_app/ui/base/base_view_model.dart';
import 'package:fzcgx_app/ui/my/factory/model/factory_product_category_model.dart';
import 'package:fzcgx_app/ui/my/factory/view_model/select_factory_products1_view_model.dart';
import 'package:fzcgx_app/ui/widget/custom_appbar_widget.dart';
import 'package:fzcgx_app/ui/widget/custom_chip_widget.dart';

class SelectFactoryProducts1Page extends StatefulWidget {
  SelectFactoryProducts1Page({Key key}) : super(key: key);

  @override
  _SelectFactoryProducts1PageState createState() =>
      _SelectFactoryProducts1PageState();
}

class _SelectFactoryProducts1PageState
    extends State<SelectFactoryProducts1Page> {
      SelectFactoryProducts1ViewModel viewModel;
      @override
  void initState() {
     viewModel= SelectFactoryProducts1ViewModel();
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return ProviderWidget<SelectFactoryProducts1ViewModel>(
        model:viewModel,
        onReady: (viewModel) {
          viewModel.requestApi();
        },
        builder: (context, viewModel, child) {
          return  viewModel.state == ViewState.Success? Scaffold(
      backgroundColor: Colors.white,
      appBar: CustomAppbar(
        title: '工厂产品',
      ),
      body:  SafeArea(
          child: SingleChildScrollView(
            child: 
                _buildSuccessWidget(viewModel)
                
          )),
      bottomNavigationBar:   Container(
          width: AdapterUtils.screenWidth(),
          height: AdapterUtils.getHeight(50),
          margin: EdgeInsets.all(15),
          child: FlatButton(
              onPressed: () {
                  viewModel.onNextStep(context);
              },
              disabledColor: Color(0xff15A1FF).withAlpha(80),
              color: Color(0xff15A1FF),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(4)),
              ),
              child: Text(
                '下一步',
                style: TextStyle(
                  fontSize: AdapterUtils.getSp(16),
                  color: Colors.white,
                  fontWeight: FontWeight.w500,
                ),
              ))),
    ):Scaffold( backgroundColor: Colors.white,);
          
        },
      ) ;
  }

  Widget _buildSuccessWidget(SelectFactoryProducts1ViewModel viewModel) {
    return SingleChildScrollView(
        child: Container(
            child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
          SizedBox(
            height: AdapterUtils.getHeight(4),
          ),
          Container(
            height: AdapterUtils.getHeight(38),
            color: Color(0xffEAF7FE),
            child: Center(
              child: Text(
                '注册填写/上传的信息越全面，客户信任度越高',
                style: TextStyle(
                  fontSize: AdapterUtils.getSp(13),
                  color: Color(0xff15A1FF),
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
          ),
          SizedBox(
            height: AdapterUtils.getHeight(18),
          ),
          Container(
            margin: EdgeInsets.symmetric(horizontal: AdapterUtils.getWidth(15)),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  '您的公司做什么产品？',
                  style: TextStyle(
                    fontSize: AdapterUtils.getSp(16),
                    color: Color(0xff3B4859),
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(
                  height: AdapterUtils.getHeight(16),
                ),
                Text(
                  '请选择，最多选择一个',
                  style: TextStyle(
                    fontSize: AdapterUtils.getSp(13),
                    color: Color(0xff99A2AD),
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(
                  height: AdapterUtils.getHeight(16),
                ),
                Wrap(
                    runSpacing: AdapterUtils.getHeight(10),
                    spacing: AdapterUtils.getWidth(10),
                    children: _buildChipWidges(viewModel)),
              ],
            ),
          ),
          SizedBox(
            height: AdapterUtils.getHeight(88),
          ),
        ])));
  }

  List<Widget> _buildChipWidges(SelectFactoryProducts1ViewModel viewModel) {
    List<Widget> lists = List<Widget>();
    viewModel.models.forEach((element) {
      lists.add(CustomChipWidget(
        model: element,
        onTap: (FactoryProductCategoryModel model) {
          viewModel.onSelectChip(model);
        },
      ));
    });

    return lists;
  }
}
